package org.leetcode.easy.leetcode26;

import java.util.Arrays;

public class Solution
{
    public static int removeDuplicates(int[] nums)
    {
        int slow =1;

        for (int fast=1;fast<nums.length;fast++) {
            if (nums[fast] != nums[fast - 1])
            {
                nums[slow]=nums[fast];
                slow++;
            }
        }

        return slow;
    }

    /**
     * 第二次编写
     * @param nums
     * @return
     */
    public static int removeDuplicates2(int[] nums){
        int slow = 0;

        for (int fast = 1; fast <nums.length ; fast++) {

            if (nums[slow]!=nums[fast])
            {
                slow++;
                nums[slow]=nums[fast];
            }
        }

        return slow+1;
    }


    public static void main(String[] args) {
        int []  nums = {1,1,2,3,3,3,5,5};

        int i = removeDuplicates2(nums);
        System.out.println(i);
        System.out.println(Arrays.toString(nums));
    }
}
